/*
package 阻塞队列案例;

class MyBlockingQueue{
    //容量
    int[] array = new int[1000];
    //对头
    int head = 0;
    //队尾
    int tail = 0;
    //当前大小
    int size = 0;
    //入队
    public void put(int key) throws InterruptedException {
        synchronized(this){
            //判断是否满了，满了就阻塞等待
            while(size >= array.length){
                this.wait();
            }
            //入队
            array[tail] = key;
            tail++;
            //判断是否溢出
            if(tail >= array.length) {
                tail = 0;
            }
            size++;
            //增加完后，就可以给唤醒take中的wait
            this.notify();
        }
    }

    //出队
    public Integer take() throws InterruptedException {
        synchronized(this){
            //判断是否为空，为空阻塞等待，while是因为等待的时间可能会有很多事情发生
            //例如interruped...
            while(size == 0){
                this.wait();
            }
            //不为空取出对头元素
            int ret = array[head];
            head++;
            //溢出
            if(head >= array.length){
                head = 0;
            }
            size--;
            //如果是满的，取出后就可以给他唤醒
            this.notify();
            return ret;
        }

    }
}
public class Test{
    static int n = 0;
    public static void main(String[] args){
        //消费者生产者模型
        MyBlockingQueue myBlockingQueue = new MyBlockingQueue();

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i = 0; i < 10; i++){
                    try {
                        myBlockingQueue.put(n);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("放入:" + n);
                    n++;
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i = 0; i < 11; i++){
                    try {
                        int n = myBlockingQueue.take();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("取出:" + n);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
*/
